package com.phison.fenestrapro.dashboard.util;
import java.util.Properties;
 
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * 
 * @author Niall O'Hara
 *
 */
public class SendMail {
 
    private String from;
    private String to1, to2, to3;
    private String subject;
    private String text;
 
    public SendMail(String from, String to1, String to2, String to3, String subject, String text){
        this.from = from;
        this.to1 = to1;
        this.to2 = to2;
        this.to3 = to3;
        this.subject = subject;
        this.text = text;
    }
 
    public void send(){
 
        Properties props = new Properties();
        props.put("mail.smtp.host", "localhost");
        props.put("mail.smtp.port", "25");
 
        Session mailSession = Session.getDefaultInstance(props);
        Message simpleMessage = new MimeMessage(mailSession);
 
        InternetAddress fromAddress = null;
        InternetAddress toAddress1 = null;
        InternetAddress toAddress2 = null;
        InternetAddress toAddress3 = null;
        try {
            fromAddress = new InternetAddress(from);
            toAddress1 = new InternetAddress(to1);
            toAddress2 = new InternetAddress(to2);
            toAddress3 = new InternetAddress(to3);
        } catch (AddressException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
 
        try {
            simpleMessage.setFrom(fromAddress);
            simpleMessage.addRecipient(RecipientType.TO, toAddress1);
            simpleMessage.addRecipient(RecipientType.TO, toAddress2);
            simpleMessage.addRecipient(RecipientType.BCC, toAddress3);
            simpleMessage.setSubject(subject);
            simpleMessage.setText(text);
 
            Transport.send(simpleMessage);
        } catch (MessagingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}